<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .adver {
            width: 300px;
            /* height: 400px; */
            background-color: aquamarine;
            position: fixed;
            right: 5px;
            bottom: 5px;
            /* display: none; */
            /* display: block; */
        }

        .adver-header {
            overflow: hidden;
            line-height: 20px;
            font-size: 13px;
            padding: 0 5px;
        }

        .adver-header .adver-title {
            float: left;
        }

        .adver-header .adver-close {
            float: right;
        }

        .adver-main img {
            width: 100%;
        }
    </style>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="app">
          <!-- 操作页面中已有的元素 -->
        <div class="adver" v-if="isShow">
            <div class="adver-header">
                <div class="adver-title">距离广告关闭还有{{countDown}}秒</div>
                <div class="adver-close" @click="closeHandler">X</div>
            </div>
            <div class="adver-main">
                <img src="../images/bzsc-dgbhz-300-250-7-5.gif" alt="">
            </div>
        </div>
    </div>
</body>
<script>
    /* 
        小广告
            (1) 页面加载完毕 等待5s 小广告显示
            (2) 倒计时10s后关闭小广告
            (3) 重复1-2
            (4) 点击关闭按钮 => 清除小广告 => 重复 1 2 3
    
    */

    var vm = new Vue({
        el:"#app",
        data:{
            isShow:false,
            delayTime: 5000,
            countDown: 10,
            countDownTimer:null,
            loop:true, // 是否重复显示小广告
        },
        methods:{
            showAdver(){
                // 等待5s 小广告显示
                setTimeout(()=>{
                    this.isShow = true;

                    // 倒计时10s后关闭小广告
                    this.countDownTimer = setInterval(()=>{
                        this.countDown--;
                        console.log(1111, this.countDown);
                        if(this.countDown == 0){
                            this.isShow = false; // 关闭广告
                            clearInterval(this.countDownTimer);

                            this.countDown = 5;

                            if(this.loop){
                                this.showAdver();
                            }
                        }
                    },1000);
                },this.delayTime)
            },
            closeHandler(){
                this.isShow = false; // 关闭广告
                clearInterval(this.countDownTimer);
            }
        },
        computed:{
            
        },
        mounted () {
            console.log(this);
            this.showAdver();
        },
        beforeDestroy () {

        }

    })


    


</script>
</html>